#pragma once
#include "db.hpp"

class Shop
{
private:
    shop_table _st;
public:
    Shop()
        :_st(g_host, g_user, g_passwd, g_db, g_port)
    {}
    ~Shop()
    {
    }
    // 1 增加
    void insert()
    {
        string name;
        double price;
        cout << "请输入商品名称和价格: ";
        cin >> name >> price;
        _st.insert(name, price);
    }
    // 2 显示所有信息
    void showAll()
    {
        string str;
        _st.showAll(str);
        cout << "---------------------------------------" << endl;
        cout << str;
        cout << "---------------------------------------" << endl;
    }
    // 3 查询-通过id
    void showById()
    {
        int id = 0;
        cout << "请输入查询的id: ";
        cin >> id;
        string str;
        _st.showById(id, str);
        cout << "---------------------------------------" << endl;
        cout << str;
        cout << "---------------------------------------" << endl;
    }
    // 4 查询-通过name
    void showByName()
    {
        string name;
        cout << "请输入查询的商品名称: ";
        cin >> name;
        string str;
        _st.showByName(name, str);
        cout << "---------------------------------------" << endl;
        cout << str;
        cout << "---------------------------------------" << endl;
    }
    // 5 删除商品-根据id
    void delById()
    {
        int id = 0;
        cout << "请输入删除的id: ";
        cin >> id;
        _st.deleteById(id);
    }
    // 6 删除商品-根据名称
    void delByName()
    {
        string name;
        cout << "请输入删除的名称: ";
        cin >> name;
        _st.deleteByName(name);
    }
    // 7 修改商品-修改数量
    void updateCount()
    {
        string name;
        cout << "请输入修改的名称: ";
        cin >> name;
        int count = 0;
        cout << "请输入增加或减少的数量: "; // 正数增加/负数减少
        cin >> count;
        _st.update_count(name, count);
    }
};